package com.wnx.action;

import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.wnx.db.UserDao;
import com.wnx.entity.Review;
import com.wnx.entity.Users;

public class UsersAction extends ActionSupport {
	private int id;
	private String introduce;
	private String phone;
	private String email;
	private Map<String,Users> dataMap = new Hashtable<>();
	private String type;
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public Map<String, Users> getDataMap() {
		return dataMap;
	}

	public String getIntroduce() {
		return introduce;
	}

	public void setIntroduce(String introduce) {
		this.introduce = introduce;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String execute() throws Exception {
		if (type.equals("upt")) {
			Users user = new Users();
			UserDao ud = new UserDao();
			user.setId(this.id);
			user.setIntroduce(this.introduce);
			user.setPhone(this.phone);
			user.setEmail(this.email);
			ud.UpdateUserByid(user);
			List<Users> users = ud.getUsersAll(this.id);
			dataMap.put("users", users.get(0));
			return SUCCESS;
		}
		if (type.equals("sel")) {
			UserDao ud = new UserDao();
			List<Users> users = ud.getUsersAll(this.id);
			dataMap.put("users", users.get(0));
			return SUCCESS;
		}

		else {
			return SUCCESS;
		}
	}
}
